package com.mibviewer.snmp;

import java.io.IOException;
import java.util.Enumeration;

import com.adventnet.snmp.mibs.MibModule;
import com.adventnet.snmp.mibs.MibOperations;
import com.mibviewer.common.HavingLifeCycle;

public class MibManager implements HavingLifeCycle
{
	private static MibManager mibManagerInstance;
	private MibOperations mibOperations;
	
	public static MibManager getMibManager()
	{
		if(mibManagerInstance==null)
		{
			mibManagerInstance = new MibManager();
		}
		return mibManagerInstance;
	}
	
	private MibManager()
	{
		mibOperations = new MibOperations();
	}
	
	public void init() throws Exception
	{
		
	}
	
	public void start() throws Exception 
	{
		
	}

	public void setMibPath(String path)
	{
		mibOperations.setMibPath(path);
	}
	
	public void addMibPath(String path)
	{
		mibOperations.setMibPath(mibOperations.getMibPath()==null ? 
				path : 
					mibOperations.getMibPath() + "|" + path);
	}

	public MibModule loadModule(String moduleName)
	{
		try
		{
			return mibOperations.loadMibModule(moduleName);
		}
		catch(Exception e)
		{
			;
		}
		return null;
	}
	
	public void showMibModules()
	{
		Enumeration modules = mibOperations.getMibModuleNames();
		while(modules.hasMoreElements())
		{
			String module = (String) modules.nextElement();
			System.out.println(module);
		}
	}
	
	public boolean stop() 
	{
		return false;
	}

	public void dispose()
	{
		mibOperations = null;
	}

}
